package com.luoqiz.file.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class SwaggerConfig {

	@Bean
	public Docket createRealTimeApi() {
		ParameterBuilder parameterBuilder = new ParameterBuilder();
		parameterBuilder.name("authorization").defaultValue("Bearer ").description("资源服务器认证Token")
				.modelRef(new ModelRef("string")).parameterType("header").required(false).build();
		List<Parameter> parameters = new ArrayList<Parameter>();
		parameters.add(parameterBuilder.build());

		return new Docket(DocumentationType.SWAGGER_2).groupName("服务测试").apiInfo(apiInfo())
				.useDefaultResponseMessages(false).globalOperationParameters(parameters).select()
				.apis(RequestHandlerSelectors.basePackage("com.luoqiz.file.controller")).paths(PathSelectors.any())
				.build();
	}

	private ApiInfo apiInfo() {
		Contact contact = new Contact("罗强征", "http://www.luoqiz.top", "851092732@qq.com");
		return new ApiInfoBuilder().title("RESTful API").contact(contact).version("1.0").build();
	}

}
